//
//  HotTableViewCell.m
//  19-homework-homeOfCar
//
//  Created by 王道林 on 16/8/9.
//  Copyright © 2016年 王道林. All rights reserved.
//

#import "HotTableViewCell.h"
#import "HotCollectionViewCell.h"
#import "List.h"
@interface HotTableViewCell ()<UICollectionViewDelegate, UICollectionViewDataSource>

@property (nonatomic, strong) UICollectionView *collectionView;
@property (nonatomic, strong) UICollectionViewFlowLayout *layout;
@end



@implementation HotTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubview];
    }
    return self;
}


- (void)createSubview
{
    _layout = [[UICollectionViewFlowLayout alloc] init];
   
    _layout.minimumLineSpacing = 0;
    _layout.minimumInteritemSpacing = 0;
    _layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    
    
    _collectionView = [[UICollectionView alloc] initWithFrame:self.contentView.bounds collectionViewLayout:_layout];
    _collectionView.backgroundColor = [UIColor whiteColor];
    [self.contentView addSubview:_collectionView];
    _collectionView.delegate = self;
    _collectionView.dataSource = self;
    
    [_collectionView registerNib:[UINib nibWithNibName:@"HotCollectionViewCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"poolCar"];
}


- (void)layoutSubviews
{
    [super layoutSubviews];
    _collectionView.frame = self.contentView.bounds;
     _layout.itemSize = CGSizeMake(self.contentView.bounds.size.width / 5, self.contentView.bounds.size.height / 2);
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
   
    return 10;
}


- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    HotCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"poolCar" forIndexPath:indexPath];
    List *list = _rootClass.result.list[indexPath.row];
    [cell setList:list];
    //cell.list = list;
    return cell;
}

- (void)setRootClass:(RootClass *)rootClass
{
    _rootClass = rootClass;
    NSLog(@"%@",_rootClass.result.list);
    [_collectionView reloadData];
}






- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
